<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>Vanilla Constants</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
function togglePopup(material_id) {
  var popup = document.getElementById(material_id);
  popup.classList.toggle("show");
}
</script>

<link href="../docs-assets/Popups.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html"><img src="../docs-assets/Inform.png" height=72> </a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=0> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="https://github.com/ganelson/inweb"><img src="../docs-assets/github.png" height=0> inweb</a></li>
<li><a href="https://github.com/ganelson/intest"><img src="../docs-assets/github.png" height=0> intest</a></li>
</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'Vanilla Constants' generated by inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../intern.html">Inter Modules</a></li><li><a href="index.html">final</a></li><li><a href="index.html#2">Chapter 2: Mechanism</a></li><li><b>Vanilla Constants</b></li></ul></div>
<p class="purpose">How the vanilla code generation strategy handles constants, including literal texts, lists, and arrays.</p>

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. </b>During the main <a href="2-vnl.html" class="internal">Vanilla</a> traverse, this is called on each constant definition
in the tree:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">VanillaConstants::constant</span><button class="popup" onclick="togglePopup('usagePopup1')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup1">Usage of <span class="code-font"><span class="function-syntax">VanillaConstants::constant</span></span>:<br/>Vanilla - <a href="2-vnl.html#SP4">&#167;4</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">code_generation</span><span class="plain-syntax"> *</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">inter_tree_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">P</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">con_name</span><span class="plain-syntax"> =</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">InterSymbolsTable::symbol_from_ID_at_node</span><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="identifier-syntax">DEFN_CONST_IFLD</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">con_name</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"no constant"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">InterSymbol::is_metadata_key</span><span class="plain-syntax">(</span><span class="identifier-syntax">con_name</span><span class="plain-syntax">) == </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">S</span><span class="plain-syntax"> = </span><span class="identifier-syntax">InterSymbol::identifier</span><span class="plain-syntax">(</span><span class="identifier-syntax">con_name</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">SymbolAnnotation::get_b</span><span class="plain-syntax">(</span><span class="identifier-syntax">con_name</span><span class="plain-syntax">, </span><span class="identifier-syntax">FAKE_ACTION_IANN</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="named-paragraph-container code-font"><a href="2-vc.html#SP1_2" class="named-paragraph-link"><span class="named-paragraph">Declare this constant as a fake action name</span><span class="named-paragraph-number">1.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Str::prefix_eq</span><span class="plain-syntax">(</span><span class="identifier-syntax">S</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"##"</span><span class="plain-syntax">, </span><span class="constant-syntax">2</span><span class="plain-syntax">))  {</span>
<span class="plain-syntax">            </span><span class="named-paragraph-container code-font"><a href="2-vc.html#SP1_1" class="named-paragraph-link"><span class="named-paragraph">Declare this constant as an action name</span><span class="named-paragraph-number">1.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">LargeScale::is_veneer_symbol</span><span class="plain-syntax">(</span><span class="identifier-syntax">con_name</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="named-paragraph-container code-font"><a href="2-vc.html#SP1_3" class="named-paragraph-link"><span class="named-paragraph">Ignore this constant as part of the veneer</span><span class="named-paragraph-number">1.3</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">SymbolAnnotation::get_b</span><span class="plain-syntax">(</span><span class="identifier-syntax">con_name</span><span class="plain-syntax">, </span><span class="identifier-syntax">OBJECT_IANN</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="named-paragraph-container code-font"><a href="2-vc.html#SP1_4" class="named-paragraph-link"><span class="named-paragraph">Declare this constant as a pseudo-object</span><span class="named-paragraph-number">1.4</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Str::eq</span><span class="plain-syntax">(</span><span class="identifier-syntax">InterSymbol::identifier</span><span class="plain-syntax">(</span><span class="identifier-syntax">con_name</span><span class="plain-syntax">), </span><span class="identifier-syntax">I</span><span class="string-syntax">"UUID_ARRAY"</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="named-paragraph-container code-font"><a href="2-vc.html#SP1_5" class="named-paragraph-link"><span class="named-paragraph">Declare this constant as the special UUID string array</span><span class="named-paragraph-number">1.5</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">        } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ConstantInstruction::list_format</span><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">CONST_LIST_FORMAT_NONE:</span><span class="plain-syntax"> </span><span class="named-paragraph-container code-font"><a href="2-vc.html#SP1_8" class="named-paragraph-link"><span class="named-paragraph">Declare this as an explicit constant</span><span class="named-paragraph-number">1.8</span></a></span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">CONST_LIST_FORMAT_SUM:</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">CONST_LIST_FORMAT_PRODUCT:</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">CONST_LIST_FORMAT_DIFFERENCE:</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">CONST_LIST_FORMAT_QUOTIENT:</span><span class="plain-syntax"> </span><span class="named-paragraph-container code-font"><a href="2-vc.html#SP1_7" class="named-paragraph-link"><span class="named-paragraph">Declare this as a computed constant</span><span class="named-paragraph-number">1.7</span></a></span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">default:</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ConstantInstruction::is_a_genuine_list_format</span><span class="plain-syntax">(</span>
<span class="plain-syntax">                    </span><span class="identifier-syntax">ConstantInstruction::list_format</span><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">))) {</span>
<span class="plain-syntax">                    </span><span class="named-paragraph-container code-font"><a href="2-vc.html#SP1_6" class="named-paragraph-link"><span class="named-paragraph">Declare this as a list constant</span><span class="named-paragraph-number">1.6</span></a></span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"ungenerated constant format"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP1_1" class="paragraph-anchor"></a><b>&#167;1.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Declare this constant as an action name</span><span class="named-paragraph-number">1.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">fa</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Str::duplicate</span><span class="plain-syntax">(</span><span class="identifier-syntax">InterSymbol::identifier</span><span class="plain-syntax">(</span><span class="identifier-syntax">con_name</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Str::delete_first_character</span><span class="plain-syntax">(</span><span class="identifier-syntax">fa</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Str::delete_first_character</span><span class="plain-syntax">(</span><span class="identifier-syntax">fa</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-cg2.html#SP7" class="function-link"><span class="function-syntax">Generators::new_action</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">fa</span><span class="plain-syntax">, </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">, </span><span class="identifier-syntax">gen</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">true_action_count</span><span class="plain-syntax">++);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">ADD_TO_LINKED_LIST</span><span class="plain-syntax">(</span><span class="identifier-syntax">fa</span><span class="plain-syntax">, </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax">, </span><span class="identifier-syntax">gen</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">actions</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-vc.html#SP1">&#167;1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP1_2" class="paragraph-anchor"></a><b>&#167;1.2. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Declare this constant as a fake action name</span><span class="named-paragraph-number">1.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">fa</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Str::duplicate</span><span class="plain-syntax">(</span><span class="identifier-syntax">InterSymbol::identifier</span><span class="plain-syntax">(</span><span class="identifier-syntax">con_name</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Str::delete_first_character</span><span class="plain-syntax">(</span><span class="identifier-syntax">fa</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Str::delete_first_character</span><span class="plain-syntax">(</span><span class="identifier-syntax">fa</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-cg2.html#SP7" class="function-link"><span class="function-syntax">Generators::new_action</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">fa</span><span class="plain-syntax">, </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">, </span><span class="constant-syntax">4096</span><span class="plain-syntax"> + </span><span class="identifier-syntax">gen</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">fake_action_count</span><span class="plain-syntax">++);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-vc.html#SP1">&#167;1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP1_3" class="paragraph-anchor"></a><b>&#167;1.3. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Ignore this constant as part of the veneer</span><span class="named-paragraph-number">1.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    ;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-vc.html#SP1">&#167;1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP1_4" class="paragraph-anchor"></a><b>&#167;1.4. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Declare this constant as a pseudo-object</span><span class="named-paragraph-number">1.4</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><a href="2-cg2.html#SP8" class="function-link"><span class="function-syntax">Generators::pseudo_object</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">InterSymbol::trans</span><span class="plain-syntax">(</span><span class="identifier-syntax">con_name</span><span class="plain-syntax">));</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-vc.html#SP1">&#167;1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP1_5" class="paragraph-anchor"></a><b>&#167;1.5. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Declare this constant as the special UUID string array</span><span class="named-paragraph-number">1.5</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">inter_pair</span><span class="plain-syntax"> </span><span class="identifier-syntax">val</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ConstantInstruction::constant</span><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">S</span><span class="plain-syntax"> = </span><span class="identifier-syntax">InterValuePairs::to_text</span><span class="plain-syntax">(</span><span class="identifier-syntax">Inode::tree</span><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">), </span><span class="identifier-syntax">val</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">segmentation_pos</span><span class="plain-syntax"> </span><span class="identifier-syntax">saved</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">content</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">length</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">content</span><span class="plain-syntax">, </span><span class="string-syntax">"UUID:</span><span class="comment-syntax">");</span>
<span class="string-syntax">    for (int i=0, L=Str::len(S); i&lt;L; i++)</span>
<span class="string-syntax">        WRITE_TO(content, "</span><span class="plain-syntax">%</span><span class="identifier-syntax">c</span><span class="string-syntax">", Characters::toupper(Str::get_at(S, i)));</span>
<span class="string-syntax">    WRITE_TO(content, "</span><span class="comment-syntax">//");</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">length</span><span class="plain-syntax">, </span><span class="string-syntax">"%d"</span><span class="plain-syntax">, (</span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">Str::len</span><span class="plain-syntax">(</span><span class="identifier-syntax">content</span><span class="plain-syntax">));</span>

<span class="plain-syntax">    </span><a href="2-cg2.html#SP10" class="function-link"><span class="function-syntax">Generators::begin_array</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"UUID_ARRAY"</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">, </span><span class="constant-syntax">BYTE_ARRAY_FORMAT</span><span class="plain-syntax">, -1, &amp;</span><span class="identifier-syntax">saved</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-cg2.html#SP10" class="function-link"><span class="function-syntax">Generators::array_entry</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">length</span><span class="plain-syntax">, </span><span class="constant-syntax">BYTE_ARRAY_FORMAT</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">LOOP_THROUGH_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">pos</span><span class="plain-syntax">, </span><span class="identifier-syntax">content</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">ch</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">ch</span><span class="plain-syntax">, </span><span class="string-syntax">"'%c'"</span><span class="plain-syntax">, </span><span class="identifier-syntax">Str::get</span><span class="plain-syntax">(</span><span class="identifier-syntax">pos</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><a href="2-cg2.html#SP10" class="function-link"><span class="function-syntax">Generators::array_entry</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">ch</span><span class="plain-syntax">, </span><span class="constant-syntax">BYTE_ARRAY_FORMAT</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">ch</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><a href="2-cg2.html#SP10" class="function-link"><span class="function-syntax">Generators::end_array</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="constant-syntax">BYTE_ARRAY_FORMAT</span><span class="plain-syntax">, -1, &amp;</span><span class="identifier-syntax">saved</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">length</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">content</span><span class="plain-syntax">)</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-vc.html#SP1">&#167;1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP1_6" class="paragraph-anchor"></a><b>&#167;1.6. </b>Inter supports four sorts of arrays, with behaviour as laid out in this 2x2 grid:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">             | </span><span class="identifier-syntax">entries</span><span class="plain-syntax"> </span><span class="identifier-syntax">count</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax">, </span><span class="constant-syntax">1</span><span class="plain-syntax">, </span><span class="constant-syntax">2</span><span class="plain-syntax">,...     | </span><span class="identifier-syntax">entry</span><span class="plain-syntax"> </span><span class="constant-syntax">0</span><span class="plain-syntax"> </span><span class="identifier-syntax">is</span><span class="plain-syntax"> </span><span class="identifier-syntax">N</span><span class="plain-syntax">, </span><span class="identifier-syntax">then</span><span class="plain-syntax"> </span><span class="identifier-syntax">entries</span><span class="plain-syntax"> </span><span class="identifier-syntax">count</span><span class="plain-syntax"> </span><span class="constant-syntax">1</span><span class="plain-syntax">, </span><span class="constant-syntax">2</span><span class="plain-syntax">, ..., </span><span class="identifier-syntax">N</span>
<span class="plain-syntax">-------------+-------------------------------+-----------------------------------------------</span>
<span class="identifier-syntax">byte</span><span class="plain-syntax"> </span><span class="identifier-syntax">entries</span><span class="plain-syntax"> | </span><span class="constant-syntax">BYTE_ARRAY_FORMAT</span><span class="plain-syntax">             | </span><span class="constant-syntax">BUFFER_ARRAY_FORMAT</span>
<span class="plain-syntax">-------------+-------------------------------+-----------------------------------------------</span>
<span class="identifier-syntax">word</span><span class="plain-syntax"> </span><span class="identifier-syntax">entries</span><span class="plain-syntax"> | </span><span class="constant-syntax">WORD_ARRAY_FORMAT</span><span class="plain-syntax">             | </span><span class="constant-syntax">TABLE_ARRAY_FORMAT</span>
<span class="plain-syntax">-------------+-------------------------------+-----------------------------------------------</span>
</pre>
<p class="commentary">Note that if an array assimilated from a kit has exactly one purported entry, then
in fact this should be interpreted as being that many blank entries. This number
must however be carefully evaluated, as it may be another constant name rather
than a literal, or may even be computed.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Declare this as a list constant</span><span class="named-paragraph-number">1.6</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">format</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ConstantInstruction::is_a_byte_format</span><span class="plain-syntax">(</span><span class="identifier-syntax">ConstantInstruction::list_format</span><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">))) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ConstantInstruction::is_a_bounded_format</span><span class="plain-syntax">(</span><span class="identifier-syntax">ConstantInstruction::list_format</span><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">)))</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">format</span><span class="plain-syntax"> = </span><span class="constant-syntax">BUFFER_ARRAY_FORMAT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">format</span><span class="plain-syntax"> = </span><span class="constant-syntax">BYTE_ARRAY_FORMAT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ConstantInstruction::is_a_bounded_format</span><span class="plain-syntax">(</span><span class="identifier-syntax">ConstantInstruction::list_format</span><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">)))</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">format</span><span class="plain-syntax"> = </span><span class="constant-syntax">TABLE_ARRAY_FORMAT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">else</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">format</span><span class="plain-syntax"> = </span><span class="constant-syntax">WORD_ARRAY_FORMAT</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">zero_count</span><span class="plain-syntax"> = -1;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">entry_count</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ConstantInstruction::list_len</span><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ConstantInstruction::is_a_by_extent_format</span><span class="plain-syntax">(</span><span class="identifier-syntax">ConstantInstruction::list_format</span><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">))) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">inter_pair</span><span class="plain-syntax"> </span><span class="identifier-syntax">val</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ConstantInstruction::list_entry</span><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="constant-syntax">0</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">zero_count</span><span class="plain-syntax"> = (</span><span class="reserved-syntax">int</span><span class="plain-syntax">) </span><span class="identifier-syntax">ConstantInstruction::evaluate</span><span class="plain-syntax">(</span><span class="identifier-syntax">InterPackage::scope_of</span><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">), </span><span class="identifier-syntax">val</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">segmentation_pos</span><span class="plain-syntax"> </span><span class="identifier-syntax">saved</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><a href="2-cg2.html#SP10" class="function-link"><span class="function-syntax">Generators::begin_array</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">InterSymbol::trans</span><span class="plain-syntax">(</span><span class="identifier-syntax">con_name</span><span class="plain-syntax">), </span><span class="identifier-syntax">con_name</span><span class="plain-syntax">, </span><span class="identifier-syntax">P</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">format</span><span class="plain-syntax">, </span><span class="identifier-syntax">zero_count</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">saved</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">zero_count</span><span class="plain-syntax"> == -1) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">entry_count</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">entry</span><span class="plain-syntax">)</span>
<span class="plain-syntax">                </span><a href="2-cg.html#SP13" class="function-link"><span class="function-syntax">CodeGen::select_temporary</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">entry</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><a href="2-cg.html#SP18" class="function-link"><span class="function-syntax">CodeGen::pair</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="identifier-syntax">ConstantInstruction::list_entry</span><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">));</span>
<span class="plain-syntax">                </span><a href="2-cg.html#SP13" class="function-link"><span class="function-syntax">CodeGen::deselect_temporary</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><a href="2-cg2.html#SP10" class="function-link"><span class="function-syntax">Generators::array_entry</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">entry</span><span class="plain-syntax">, </span><span class="identifier-syntax">format</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">entry</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><a href="2-cg2.html#SP10" class="function-link"><span class="function-syntax">Generators::end_array</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">format</span><span class="plain-syntax">, </span><span class="identifier-syntax">zero_count</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">saved</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-vc.html#SP1">&#167;1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP1_7" class="paragraph-anchor"></a><b>&#167;1.7. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Declare this as a computed constant</span><span class="named-paragraph-number">1.7</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><a href="2-cg2.html#SP11" class="function-link"><span class="function-syntax">Generators::declare_constant</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">con_name</span><span class="plain-syntax">, </span><span class="constant-syntax">COMPUTED_GDCFORM</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-vc.html#SP1">&#167;1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP1_8" class="paragraph-anchor"></a><b>&#167;1.8. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Declare this as an explicit constant</span><span class="named-paragraph-number">1.8</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">inter_pair</span><span class="plain-syntax"> </span><span class="identifier-syntax">val</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ConstantInstruction::constant</span><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">InterValuePairs::is_text</span><span class="plain-syntax">(</span><span class="identifier-syntax">val</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">S</span><span class="plain-syntax"> = </span><span class="identifier-syntax">InterValuePairs::to_text</span><span class="plain-syntax">(</span><span class="identifier-syntax">Inode::tree</span><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">), </span><span class="identifier-syntax">val</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><a href="2-vc.html#SP3" class="function-link"><span class="function-syntax">VanillaConstants::defer_declaring_literal_text</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">S</span><span class="plain-syntax">, </span><span class="identifier-syntax">con_name</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><a href="2-cg2.html#SP11" class="function-link"><span class="function-syntax">Generators::declare_constant</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">con_name</span><span class="plain-syntax">, </span><span class="constant-syntax">DATA_GDCFORM</span><span class="plain-syntax">, </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="2-vc.html#SP1">&#167;1</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. </b>When called by <a href="2-cg2.html#SP11" class="internal">Generators::declare_constant</a>, generators may if they choose
make use of the following convenient function for generating the value to which a
constant name is given.
</p>

<p class="commentary">Note that this assumes that the usual arithmetic operators and brackets can be
used in the syntax for literal quantities: e.g., it may produce <span class="extract"><span class="extract-syntax">(A + (3 * B))</span></span>
for constants <span class="extract"><span class="extract-syntax">A</span></span>, <span class="extract"><span class="extract-syntax">B</span></span>. If the generator is for a language which doesn't allow
that, it will have to make other arrangements.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">VanillaConstants::definition_value</span><button class="popup" onclick="togglePopup('usagePopup2')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup2">Usage of <span class="code-font"><span class="function-syntax">VanillaConstants::definition_value</span></span>:<br/>Inform 6 Constants - <a href="4-i6c.html#SP2">&#167;2</a>, <a href="4-i6c.html#SP2_4">&#167;2.4</a>, <a href="4-i6c.html#SP2_5">&#167;2.5</a><br/>C Namespace - <a href="5-cnm.html#SP7">&#167;7</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">code_generation</span><span class="plain-syntax"> *</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">form</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">con_name</span><span class="plain-syntax">, </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">val</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">inter_tree_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">P</span><span class="plain-syntax"> = </span><span class="identifier-syntax">con_name</span><span class="plain-syntax">-&gt;</span><span class="identifier-syntax">definition</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">OUT</span><span class="plain-syntax"> = </span><a href="2-cg.html#SP14" class="function-link"><span class="function-syntax">CodeGen::current</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">form</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">RAW_GDCFORM:</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Str::len</span><span class="plain-syntax">(</span><span class="identifier-syntax">val</span><span class="plain-syntax">) &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"%S"</span><span class="plain-syntax">, </span><span class="identifier-syntax">val</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">                </span><a href="2-cg2.html#SP20" class="function-link"><span class="function-syntax">Generators::compile_literal_number</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="constant-syntax">1</span><span class="plain-syntax">, </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">MANGLED_GDCFORM:</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">Str::len</span><span class="plain-syntax">(</span><span class="identifier-syntax">val</span><span class="plain-syntax">) &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">                </span><a href="2-cg2.html#SP16" class="function-link"><span class="function-syntax">Generators::mangle</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">OUT</span><span class="plain-syntax">, </span><span class="identifier-syntax">val</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">                </span><a href="2-cg2.html#SP20" class="function-link"><span class="function-syntax">Generators::compile_literal_number</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="constant-syntax">1</span><span class="plain-syntax">, </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">DATA_GDCFORM:</span>
<span class="plain-syntax">            </span><a href="2-cg.html#SP18" class="function-link"><span class="function-syntax">CodeGen::pair</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="identifier-syntax">ConstantInstruction::constant</span><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">));</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">COMPUTED_GDCFORM:</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"("</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">ConstantInstruction::list_len</span><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">); </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">i</span><span class="plain-syntax">&gt;0) {</span>
<span class="plain-syntax">                    </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ConstantInstruction::list_format</span><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">)) {</span>
<span class="plain-syntax">                        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">CONST_LIST_FORMAT_SUM:</span><span class="plain-syntax">        </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">" + "</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">CONST_LIST_FORMAT_PRODUCT:</span><span class="plain-syntax">    </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">" * "</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">CONST_LIST_FORMAT_DIFFERENCE:</span><span class="plain-syntax"> </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">" - "</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">CONST_LIST_FORMAT_QUOTIENT:</span><span class="plain-syntax">   </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">" / "</span><span class="plain-syntax">); </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                    }</span>
<span class="plain-syntax">                }</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">bracket</span><span class="plain-syntax"> = </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">inter_pair</span><span class="plain-syntax"> </span><span class="identifier-syntax">operand</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ConstantInstruction::list_entry</span><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="identifier-syntax">i</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">InterValuePairs::is_number</span><span class="plain-syntax">(</span><span class="identifier-syntax">operand</span><span class="plain-syntax">)) ||</span>
<span class="plain-syntax">                    (</span><span class="identifier-syntax">InterValuePairs::is_symbolic</span><span class="plain-syntax">(</span><span class="identifier-syntax">operand</span><span class="plain-syntax">))) </span><span class="identifier-syntax">bracket</span><span class="plain-syntax"> = </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">bracket</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"("</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><a href="2-cg.html#SP18" class="function-link"><span class="function-syntax">CodeGen::pair</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="identifier-syntax">operand</span><span class="plain-syntax">);</span>
<span class="plain-syntax">                </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">bracket</span><span class="plain-syntax">) </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">")"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            }</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">")"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">LITERAL_TEXT_GDCFORM:</span>
<span class="plain-syntax">            </span><a href="2-cg2.html#SP20" class="function-link"><span class="function-syntax">Generators::compile_literal_text</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">val</span><span class="plain-syntax">, </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. </b>During the above process, a constant set equal to a text literal is not
immediately declared: instead, the following mechanism is used to stash it for
later.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">text_literal_holder</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">literal_content</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">con_name</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">CLASS_DEFINITION</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">text_literal_holder</span><span class="plain-syntax">;</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">VanillaConstants::defer_declaring_literal_text</span><button class="popup" onclick="togglePopup('usagePopup3')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup3">Usage of <span class="code-font"><span class="function-syntax">VanillaConstants::defer_declaring_literal_text</span></span>:<br/><a href="2-vc.html#SP1_8">&#167;1.8</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">code_generation</span><span class="plain-syntax"> *</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">S</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">con_name</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">text_literal_holder</span><span class="plain-syntax"> *</span><span class="identifier-syntax">tlh</span><span class="plain-syntax"> = </span><span class="identifier-syntax">CREATE</span><span class="plain-syntax">(</span><span class="reserved-syntax">text_literal_holder</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">tlh</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">literal_content</span><span class="plain-syntax"> = </span><span class="identifier-syntax">S</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">tlh</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">con_name</span><span class="plain-syntax"> = </span><span class="identifier-syntax">con_name</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">ADD_TO_LINKED_LIST</span><span class="plain-syntax">(</span><span class="identifier-syntax">tlh</span><span class="plain-syntax">, </span><span class="reserved-syntax">text_literal_holder</span><span class="plain-syntax">, </span><span class="identifier-syntax">gen</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">text_literals</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<ul class="endnotetexts"><li>The structure text_literal_holder is private to this section.</li></ul>
<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. </b>And now it's later. We go through all of the stashed text literals, and sort
them into alphabetical order; and then declare them. What this whole business
achieves, then, is to declare text constants in alphabetical order rather than
in tree order.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">VanillaConstants::declare_text_literals</span><button class="popup" onclick="togglePopup('usagePopup4')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup4">Usage of <span class="code-font"><span class="function-syntax">VanillaConstants::declare_text_literals</span></span>:<br/>Vanilla - <a href="2-vnl.html#SP1">&#167;1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">code_generation</span><span class="plain-syntax"> *</span><span class="identifier-syntax">gen</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">no_tlh</span><span class="plain-syntax"> = </span><span class="identifier-syntax">LinkedLists::len</span><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">text_literals</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">no_tlh</span><span class="plain-syntax"> &gt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">text_literal_holder</span><span class="plain-syntax"> **</span><span class="identifier-syntax">sorted</span><span class="plain-syntax"> = (</span><span class="reserved-syntax">text_literal_holder</span><span class="plain-syntax"> **)</span>
<span class="plain-syntax">            (</span><span class="identifier-syntax">Memory::calloc</span><span class="plain-syntax">(</span><span class="identifier-syntax">no_tlh</span><span class="plain-syntax">, </span><span class="reserved-syntax">sizeof</span><span class="plain-syntax">(</span><span class="reserved-syntax">text_literal_holder</span><span class="plain-syntax"> *), </span><span class="constant-syntax">CODE_GENERATION_MREASON</span><span class="plain-syntax">));</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">text_literal_holder</span><span class="plain-syntax"> *</span><span class="identifier-syntax">tlh</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">LOOP_OVER_LINKED_LIST</span><span class="plain-syntax">(</span><span class="identifier-syntax">tlh</span><span class="plain-syntax">, </span><span class="reserved-syntax">text_literal_holder</span><span class="plain-syntax">, </span><span class="identifier-syntax">gen</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">text_literals</span><span class="plain-syntax">)</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">sorted</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">++] = </span><span class="identifier-syntax">tlh</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">qsort</span><span class="plain-syntax">(</span><span class="identifier-syntax">sorted</span><span class="plain-syntax">, (</span><span class="identifier-syntax">size_t</span><span class="plain-syntax">) </span><span class="identifier-syntax">no_tlh</span><span class="plain-syntax">, </span><span class="reserved-syntax">sizeof</span><span class="plain-syntax">(</span><span class="reserved-syntax">text_literal_holder</span><span class="plain-syntax"> *),</span>
<span class="plain-syntax">            </span><a href="2-vc.html#SP5" class="function-link"><span class="function-syntax">VanillaConstants::compare_tlh</span></a><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">no_tlh</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) {</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">text_literal_holder</span><span class="plain-syntax"> *</span><span class="identifier-syntax">tlh</span><span class="plain-syntax"> = </span><span class="identifier-syntax">sorted</span><span class="plain-syntax">[</span><span class="identifier-syntax">i</span><span class="plain-syntax">];</span>
<span class="plain-syntax">            </span><a href="2-cg2.html#SP11" class="function-link"><span class="function-syntax">Generators::declare_constant</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">tlh</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">con_name</span><span class="plain-syntax">, </span><span class="constant-syntax">LITERAL_TEXT_GDCFORM</span><span class="plain-syntax">,</span>
<span class="plain-syntax">                </span><span class="identifier-syntax">tlh</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">literal_content</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. </b>Note that <span class="extract"><span class="extract-syntax">Str::cmp</span></span> is a case-sensitive comparison, so <span class="extract"><span class="extract-syntax">Zebra</span></span> will come
before <span class="extract"><span class="extract-syntax">armadillo</span></span>, for example, <span class="extract"><span class="extract-syntax">Z</span></span> being before <span class="extract"><span class="extract-syntax">a</span></span> in Unicode.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">VanillaConstants::compare_tlh</span><button class="popup" onclick="togglePopup('usagePopup5')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup5">Usage of <span class="code-font"><span class="function-syntax">VanillaConstants::compare_tlh</span></span>:<br/><a href="2-vc.html#SP4">&#167;4</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">const</span><span class="plain-syntax"> </span><span class="reserved-syntax">void</span><span class="plain-syntax"> *</span><span class="identifier-syntax">elem1</span><span class="plain-syntax">, </span><span class="reserved-syntax">const</span><span class="plain-syntax"> </span><span class="reserved-syntax">void</span><span class="plain-syntax"> *</span><span class="identifier-syntax">elem2</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">const</span><span class="plain-syntax"> </span><span class="reserved-syntax">text_literal_holder</span><span class="plain-syntax"> **</span><span class="identifier-syntax">e1</span><span class="plain-syntax"> = (</span><span class="reserved-syntax">const</span><span class="plain-syntax"> </span><span class="reserved-syntax">text_literal_holder</span><span class="plain-syntax"> **) </span><span class="identifier-syntax">elem1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">const</span><span class="plain-syntax"> </span><span class="reserved-syntax">text_literal_holder</span><span class="plain-syntax"> **</span><span class="identifier-syntax">e2</span><span class="plain-syntax"> = (</span><span class="reserved-syntax">const</span><span class="plain-syntax"> </span><span class="reserved-syntax">text_literal_holder</span><span class="plain-syntax"> **) </span><span class="identifier-syntax">elem2</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((*</span><span class="identifier-syntax">e1</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">) || (*</span><span class="identifier-syntax">e2</span><span class="plain-syntax"> == </span><span class="identifier-syntax">NULL</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"Disaster while sorting text literals"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">s1</span><span class="plain-syntax"> = (*</span><span class="identifier-syntax">e1</span><span class="plain-syntax">)-&gt;</span><span class="element-syntax">literal_content</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">s2</span><span class="plain-syntax"> = (*</span><span class="identifier-syntax">e2</span><span class="plain-syntax">)-&gt;</span><span class="element-syntax">literal_content</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">Str::cmp</span><span class="plain-syntax">(</span><span class="identifier-syntax">s1</span><span class="plain-syntax">, </span><span class="identifier-syntax">s2</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP6" class="paragraph-anchor"></a><b>&#167;6. </b>The remainder of this section is given over to a utility function which
generators may want to use: it turns an Inter-notation text for a real number
into an unsigned 32-bit integer which can represent that number at runtime
(provided we are on a 32-bit computer: the Z-machine need not apply).
</p>

<p class="commentary">No error messages should be printed, of course, because the syntax should have
been checked before the text here entered the Inter hierarchy.
</p>

<p class="commentary">The code below is adapted from additions made by Andrew Plotkin to the Inform 6
compiler to accommodate floating-point arithmetic.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">uint32_t</span><span class="plain-syntax"> </span><span class="function-syntax">VanillaConstants::textual_real_to_uint32</span><button class="popup" onclick="togglePopup('usagePopup6')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup6">Usage of <span class="code-font"><span class="function-syntax">VanillaConstants::textual_real_to_uint32</span></span>:<br/>C Literals - <a href="5-clt.html#SP4">&#167;4</a></span></button><span class="plain-syntax">(</span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">T</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">at</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">inchar32_t</span><span class="plain-syntax"> </span><span class="identifier-syntax">lookahead</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Str::get_at</span><span class="plain-syntax">(</span><span class="identifier-syntax">T</span><span class="plain-syntax">, </span><span class="identifier-syntax">at</span><span class="plain-syntax">++);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">expo</span><span class="plain-syntax">=0; </span><span class="reserved-syntax">double</span><span class="plain-syntax"> </span><span class="identifier-syntax">intv</span><span class="plain-syntax">=0, </span><span class="identifier-syntax">fracv</span><span class="plain-syntax">=0;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">expocount</span><span class="plain-syntax">=0, </span><span class="identifier-syntax">intcount</span><span class="plain-syntax">=0, </span><span class="identifier-syntax">fraccount</span><span class="plain-syntax">=0, </span><span class="identifier-syntax">signbit</span><span class="plain-syntax">=0;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">lookahead</span><span class="plain-syntax"> == </span><span class="character-syntax">'-'</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">signbit</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">lookahead</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Str::get_at</span><span class="plain-syntax">(</span><span class="identifier-syntax">T</span><span class="plain-syntax">, </span><span class="identifier-syntax">at</span><span class="plain-syntax">++);</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">lookahead</span><span class="plain-syntax"> == </span><span class="character-syntax">'+'</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">signbit</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">lookahead</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Str::get_at</span><span class="plain-syntax">(</span><span class="identifier-syntax">T</span><span class="plain-syntax">, </span><span class="identifier-syntax">at</span><span class="plain-syntax">++);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><a href="2-vc.html#SP6" class="function-link"><span class="function-syntax">VanillaConstants::character_digit_value</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">lookahead</span><span class="plain-syntax">) &lt; </span><span class="constant-syntax">10</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">intv</span><span class="plain-syntax"> = </span><span class="constant-syntax">10</span><span class="plain-syntax">.0*</span><span class="identifier-syntax">intv</span><span class="plain-syntax"> + </span><a href="2-vc.html#SP6" class="function-link"><span class="function-syntax">VanillaConstants::character_digit_value</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">lookahead</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">intcount</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">lookahead</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Str::get_at</span><span class="plain-syntax">(</span><span class="identifier-syntax">T</span><span class="plain-syntax">, </span><span class="identifier-syntax">at</span><span class="plain-syntax">++);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">lookahead</span><span class="plain-syntax"> == </span><span class="character-syntax">'.'</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">double</span><span class="plain-syntax"> </span><span class="identifier-syntax">fracpow</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">.0;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">lookahead</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Str::get_at</span><span class="plain-syntax">(</span><span class="identifier-syntax">T</span><span class="plain-syntax">, </span><span class="identifier-syntax">at</span><span class="plain-syntax">++);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><a href="2-vc.html#SP6" class="function-link"><span class="function-syntax">VanillaConstants::character_digit_value</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">lookahead</span><span class="plain-syntax">) &lt; </span><span class="constant-syntax">10</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">fracpow</span><span class="plain-syntax"> *= </span><span class="constant-syntax">0</span><span class="plain-syntax">.1;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">fracv</span><span class="plain-syntax"> = </span><span class="identifier-syntax">fracv</span><span class="plain-syntax"> + </span><span class="identifier-syntax">fracpow</span><span class="plain-syntax">*</span><a href="2-vc.html#SP6" class="function-link"><span class="function-syntax">VanillaConstants::character_digit_value</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">lookahead</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">fraccount</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">lookahead</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Str::get_at</span><span class="plain-syntax">(</span><span class="identifier-syntax">T</span><span class="plain-syntax">, </span><span class="identifier-syntax">at</span><span class="plain-syntax">++);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">lookahead</span><span class="plain-syntax"> == </span><span class="character-syntax">'e'</span><span class="plain-syntax"> || </span><span class="identifier-syntax">lookahead</span><span class="plain-syntax"> == </span><span class="character-syntax">'E'</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">exposign</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">lookahead</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Str::get_at</span><span class="plain-syntax">(</span><span class="identifier-syntax">T</span><span class="plain-syntax">, </span><span class="identifier-syntax">at</span><span class="plain-syntax">++);</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">lookahead</span><span class="plain-syntax"> == </span><span class="character-syntax">'+'</span><span class="plain-syntax"> || </span><span class="identifier-syntax">lookahead</span><span class="plain-syntax"> == </span><span class="character-syntax">'-'</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">exposign</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">lookahead</span><span class="plain-syntax"> == </span><span class="character-syntax">'-'</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">lookahead</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Str::get_at</span><span class="plain-syntax">(</span><span class="identifier-syntax">T</span><span class="plain-syntax">, </span><span class="identifier-syntax">at</span><span class="plain-syntax">++);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">while</span><span class="plain-syntax"> (</span><a href="2-vc.html#SP6" class="function-link"><span class="function-syntax">VanillaConstants::character_digit_value</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">lookahead</span><span class="plain-syntax">) &lt; </span><span class="constant-syntax">10</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">expo</span><span class="plain-syntax"> = </span><span class="constant-syntax">10</span><span class="plain-syntax">*</span><span class="identifier-syntax">expo</span><span class="plain-syntax"> + </span><a href="2-vc.html#SP6" class="function-link"><span class="function-syntax">VanillaConstants::character_digit_value</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">lookahead</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">expocount</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">lookahead</span><span class="plain-syntax"> = </span><span class="identifier-syntax">Str::get_at</span><span class="plain-syntax">(</span><span class="identifier-syntax">T</span><span class="plain-syntax">, </span><span class="identifier-syntax">at</span><span class="plain-syntax">++);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">expocount</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">STDERR</span><span class="plain-syntax">, </span><span class="string-syntax">"Floating-point literal '%S' must have digits after the 'e'"</span><span class="plain-syntax">, </span><span class="identifier-syntax">T</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"bad floating-point literal"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        }</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">exposign</span><span class="plain-syntax">) { </span><span class="identifier-syntax">expo</span><span class="plain-syntax"> = -</span><span class="identifier-syntax">expo</span><span class="plain-syntax">; }</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">intcount</span><span class="plain-syntax"> + </span><span class="identifier-syntax">fraccount</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">STDERR</span><span class="plain-syntax">, </span><span class="string-syntax">"Floating-point literal '%S' must have digits"</span><span class="plain-syntax">, </span><span class="identifier-syntax">T</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">internal_error</span><span class="plain-syntax">(</span><span class="string-syntax">"bad floating-point literal"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><a href="2-vc.html#SP8" class="function-link"><span class="function-syntax">VanillaConstants::real_components_to_uint32</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">signbit</span><span class="plain-syntax">, </span><span class="identifier-syntax">intv</span><span class="plain-syntax">, </span><span class="identifier-syntax">fracv</span><span class="plain-syntax">, </span><span class="identifier-syntax">expo</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">VanillaConstants::character_digit_value</span><span class="plain-syntax">(</span><span class="identifier-syntax">inchar32_t</span><span class="plain-syntax"> </span><span class="identifier-syntax">c</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">c</span><span class="plain-syntax"> &gt;= </span><span class="character-syntax">'0'</span><span class="plain-syntax">) &amp;&amp; (</span><span class="identifier-syntax">c</span><span class="plain-syntax"> &lt;= </span><span class="character-syntax">'9'</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> (</span><span class="reserved-syntax">int</span><span class="plain-syntax">) (</span><span class="identifier-syntax">c</span><span class="plain-syntax"> - </span><span class="character-syntax">'0'</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="constant-syntax">10</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP7" class="paragraph-anchor"></a><b>&#167;7. </b>And this returns 10 raised to the power <span class="extract"><span class="extract-syntax">expo</span></span>, which is an integer. Andrew
Plotkin refers to this as "cheap" because it avoids the C library <span class="extract"><span class="extract-syntax">pow10</span></span>,
which is awkward on some platforms.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">#</span><span class="identifier-syntax">ifndef</span><span class="plain-syntax"> </span><span class="identifier-syntax">POW10_RANGE</span>
<span class="plain-syntax">#</span><span class="identifier-syntax">define</span><span class="plain-syntax"> </span><span class="identifier-syntax">POW10_RANGE</span><span class="plain-syntax"> (8)</span>
<span class="plain-syntax">#</span><span class="identifier-syntax">endif</span>

<span class="reserved-syntax">double</span><span class="plain-syntax"> </span><span class="function-syntax">VanillaConstants::pow10_cheap</span><button class="popup" onclick="togglePopup('usagePopup7')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup7">Usage of <span class="code-font"><span class="function-syntax">VanillaConstants::pow10_cheap</span></span>:<br/><a href="2-vc.html#SP8">&#167;8</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">expo</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">static</span><span class="plain-syntax"> </span><span class="reserved-syntax">double</span><span class="plain-syntax"> </span><span class="identifier-syntax">powers</span><span class="plain-syntax">[</span><span class="identifier-syntax">POW10_RANGE</span><span class="plain-syntax">*2+1] = {</span>
<span class="plain-syntax">        </span><span class="constant-syntax">0</span><span class="plain-syntax">.00000001, </span><span class="constant-syntax">0</span><span class="plain-syntax">.0000001, </span><span class="constant-syntax">0</span><span class="plain-syntax">.000001, </span><span class="constant-syntax">0</span><span class="plain-syntax">.00001, </span><span class="constant-syntax">0</span><span class="plain-syntax">.0001, </span><span class="constant-syntax">0</span><span class="plain-syntax">.001, </span><span class="constant-syntax">0</span><span class="plain-syntax">.01, </span><span class="constant-syntax">0</span><span class="plain-syntax">.1,</span>
<span class="plain-syntax">        </span><span class="constant-syntax">1</span><span class="plain-syntax">.0,</span>
<span class="plain-syntax">        </span><span class="constant-syntax">10</span><span class="plain-syntax">.0, </span><span class="constant-syntax">100</span><span class="plain-syntax">.0, </span><span class="constant-syntax">1000</span><span class="plain-syntax">.0, </span><span class="constant-syntax">10000</span><span class="plain-syntax">.0, </span><span class="constant-syntax">100000</span><span class="plain-syntax">.0, </span><span class="constant-syntax">1000000</span><span class="plain-syntax">.0, </span><span class="constant-syntax">10000000</span><span class="plain-syntax">.0, </span><span class="constant-syntax">100000000</span><span class="plain-syntax">.0</span>
<span class="plain-syntax">    };</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">double</span><span class="plain-syntax"> </span><span class="identifier-syntax">res</span><span class="plain-syntax"> = </span><span class="constant-syntax">1</span><span class="plain-syntax">.0;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">expo</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">0</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (; </span><span class="identifier-syntax">expo</span><span class="plain-syntax"> &lt; -</span><span class="identifier-syntax">POW10_RANGE</span><span class="plain-syntax">; </span><span class="identifier-syntax">expo</span><span class="plain-syntax"> += </span><span class="identifier-syntax">POW10_RANGE</span><span class="plain-syntax">) </span><span class="identifier-syntax">res</span><span class="plain-syntax"> *= </span><span class="identifier-syntax">powers</span><span class="plain-syntax">[0];</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">res</span><span class="plain-syntax"> * </span><span class="identifier-syntax">powers</span><span class="plain-syntax">[</span><span class="identifier-syntax">POW10_RANGE</span><span class="plain-syntax">+</span><span class="identifier-syntax">expo</span><span class="plain-syntax">];</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (; </span><span class="identifier-syntax">expo</span><span class="plain-syntax"> &gt; </span><span class="identifier-syntax">POW10_RANGE</span><span class="plain-syntax">; </span><span class="identifier-syntax">expo</span><span class="plain-syntax"> -= </span><span class="identifier-syntax">POW10_RANGE</span><span class="plain-syntax">) </span><span class="identifier-syntax">res</span><span class="plain-syntax"> *= </span><span class="identifier-syntax">powers</span><span class="plain-syntax">[</span><span class="identifier-syntax">POW10_RANGE</span><span class="plain-syntax">*2];</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">res</span><span class="plain-syntax"> * </span><span class="identifier-syntax">powers</span><span class="plain-syntax">[</span><span class="identifier-syntax">POW10_RANGE</span><span class="plain-syntax">+</span><span class="identifier-syntax">expo</span><span class="plain-syntax">];</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP8" class="paragraph-anchor"></a><b>&#167;8. </b>Finally, this function returns the IEEE-754 single-precision encoding of a
floating-point number from its various components.
</p>

<p class="commentary">See <a href="http://www.psc.edu/general/software/packages/ieee/ieee.php" class="external">http://www.psc.edu/general/software/packages/ieee/ieee.php</a> for an explanation.
</p>

<p class="commentary">If the magnitude is too large (beyond about 3.4e+38), this returns
an infinite value (0x7f800000 or 0xff800000). If the magnitude is too
small (below about 1e-45), this returns a zero value (0x00000000 or
0x80000000). If any of the inputs are NaN, this returns NaN.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">uint32_t</span><span class="plain-syntax"> </span><span class="function-syntax">VanillaConstants::real_components_to_uint32</span><button class="popup" onclick="togglePopup('usagePopup8')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup8">Usage of <span class="code-font"><span class="function-syntax">VanillaConstants::real_components_to_uint32</span></span>:<br/><a href="2-vc.html#SP6">&#167;6</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">signbit</span><span class="plain-syntax">, </span><span class="reserved-syntax">double</span><span class="plain-syntax"> </span><span class="identifier-syntax">intv</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">double</span><span class="plain-syntax"> </span><span class="identifier-syntax">fracv</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">expo</span><span class="plain-syntax">) {</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">double</span><span class="plain-syntax"> </span><span class="identifier-syntax">absval</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">intv</span><span class="plain-syntax"> + </span><span class="identifier-syntax">fracv</span><span class="plain-syntax">) * </span><a href="2-vc.html#SP7" class="function-link"><span class="function-syntax">VanillaConstants::pow10_cheap</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">expo</span><span class="plain-syntax">);</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">uint32_t</span><span class="plain-syntax"> </span><span class="identifier-syntax">sign</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">signbit</span><span class="plain-syntax"> ? </span><span class="constant-syntax">0x80000000</span><span class="plain-syntax"> : </span><span class="constant-syntax">0x0</span><span class="plain-syntax">);</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">isinf</span><span class="plain-syntax">(</span><span class="identifier-syntax">absval</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">sign</span><span class="plain-syntax"> | </span><span class="constant-syntax">0x7f800000</span><span class="plain-syntax">; </span><span class="comment-syntax"> infinity</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">isnan</span><span class="plain-syntax">(</span><span class="identifier-syntax">absval</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">sign</span><span class="plain-syntax"> | </span><span class="constant-syntax">0x7fc00000</span><span class="plain-syntax">; </span><span class="comment-syntax"> NaN</span>

<span class="plain-syntax">   </span><span class="reserved-syntax">double</span><span class="plain-syntax"> </span><span class="identifier-syntax">mant</span><span class="plain-syntax"> = </span><span class="identifier-syntax">frexp</span><span class="plain-syntax">(</span><span class="identifier-syntax">absval</span><span class="plain-syntax">, &amp;</span><span class="identifier-syntax">expo</span><span class="plain-syntax">);</span>

<span class="plain-syntax">    </span><span class="comment-syntax"> Normalize mantissa to be in the range [1.0, 2.0)</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (0.5 &lt;= </span><span class="identifier-syntax">mant</span><span class="plain-syntax"> &amp;&amp; </span><span class="identifier-syntax">mant</span><span class="plain-syntax"> &lt; </span><span class="constant-syntax">1</span><span class="plain-syntax">.0) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">mant</span><span class="plain-syntax"> *= </span><span class="constant-syntax">2</span><span class="plain-syntax">.0;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">expo</span><span class="plain-syntax">--;</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">mant</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">.0) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">expo</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">sign</span><span class="plain-syntax"> | </span><span class="constant-syntax">0x7f800000</span><span class="plain-syntax">; </span><span class="comment-syntax"> infinity</span>
<span class="plain-syntax">    }</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">expo</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">128</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">sign</span><span class="plain-syntax"> | </span><span class="constant-syntax">0x7f800000</span><span class="plain-syntax">; </span><span class="comment-syntax"> infinity</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">expo</span><span class="plain-syntax"> &lt; -126) {</span>
<span class="plain-syntax">        </span><span class="comment-syntax"> Denormalized (very small) number</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">mant</span><span class="plain-syntax"> = </span><span class="identifier-syntax">ldexp</span><span class="plain-syntax">(</span><span class="identifier-syntax">mant</span><span class="plain-syntax">, </span><span class="constant-syntax">126</span><span class="plain-syntax"> + </span><span class="identifier-syntax">expo</span><span class="plain-syntax">);</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">expo</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    } </span><span class="reserved-syntax">else</span><span class="plain-syntax"> </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (!(</span><span class="identifier-syntax">expo</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax"> &amp;&amp; </span><span class="identifier-syntax">mant</span><span class="plain-syntax"> == </span><span class="constant-syntax">0</span><span class="plain-syntax">.0)) {</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">expo</span><span class="plain-syntax"> += </span><span class="constant-syntax">127</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">mant</span><span class="plain-syntax"> -= </span><span class="constant-syntax">1</span><span class="plain-syntax">.0; </span><span class="comment-syntax"> Get rid of leading 1</span>
<span class="plain-syntax">    }</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">mant</span><span class="plain-syntax"> *= </span><span class="constant-syntax">8388608</span><span class="plain-syntax">.0; </span><span class="comment-syntax"> 2^23</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">uint32_t</span><span class="plain-syntax"> </span><span class="identifier-syntax">fbits</span><span class="plain-syntax"> = (</span><span class="identifier-syntax">uint32_t</span><span class="plain-syntax">)(</span><span class="identifier-syntax">mant</span><span class="plain-syntax"> + </span><span class="constant-syntax">0</span><span class="plain-syntax">.5); </span><span class="comment-syntax"> round mant to nearest int</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">fbits</span><span class="plain-syntax"> &gt;&gt; </span><span class="constant-syntax">23</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="comment-syntax"> The carry propagated out of a string of 23 1 bits.</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">fbits</span><span class="plain-syntax"> = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">expo</span><span class="plain-syntax">++;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">expo</span><span class="plain-syntax"> &gt;= </span><span class="constant-syntax">255</span><span class="plain-syntax">) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">sign</span><span class="plain-syntax"> | </span><span class="constant-syntax">0x7f800000</span><span class="plain-syntax">; </span><span class="comment-syntax"> infinity</span>
<span class="plain-syntax">    }</span>

<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> (</span><span class="identifier-syntax">sign</span><span class="plain-syntax">) | ((</span><span class="identifier-syntax">uint32_t</span><span class="plain-syntax">)(</span><span class="identifier-syntax">expo</span><span class="plain-syntax"> &lt;&lt; </span><span class="constant-syntax">23</span><span class="plain-syntax">)) | (</span><span class="identifier-syntax">fbits</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="2-vnl.html">&#10094;</a></li><li class="progresschapter"><a href="P-wtmd.html">P</a></li><li class="progresschapter"><a href="1-fm.html">1</a></li><li class="progresscurrentchapter">2</li><li class="progresssection"><a href="2-cg.html">cg</a></li><li class="progresssection"><a href="2-cg2.html">cg2</a></li><li class="progresssection"><a href="2-vnl.html">vnl</a></li><li class="progresscurrent">vc</li><li class="progresssection"><a href="2-vf.html">vf</a></li><li class="progresssection"><a href="2-vo.html">vo</a></li><li class="progresssection"><a href="2-vc2.html">vc2</a></li><li class="progresssection"><a href="2-vi.html">vi</a></li><li class="progresschapter"><a href="3-fti.html">3</a></li><li class="progresschapter"><a href="4-fi6.html">4</a></li><li class="progresschapter"><a href="5-fnc.html">5</a></li><li class="progressnext"><a href="2-vf.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

